package cn.com.zetatech.loader.resolver.service.impl;

import cn.com.zetatech.loader.resolver.service.EnumFileParserStrategy;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class EnumCSVFileParser implements EnumFileParserStrategy {

    public static class Person {
        private String name;
        private int age;
        private String email;

        public Person(String name, int age, String email) {
            this.name = name;
            this.age = age;
            this.email = email;
        }

        @Override
        public String toString() {
            return "Person{name='" + name + "', age=" + age + ", email='" + email + "'}";
        }
    }

    @Override
    public List<Person> parse(String filePath) {
        List<Person> people = new ArrayList<>();
        String line;

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            br.readLine(); // Skip header

            while ((line = br.readLine()) != null) {
                String[] values = line.split(",");
                String name = values[0];
                int age = Integer.parseInt(values[1]);
                String email = values[2];
                people.add(new Person(name, age, email));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return people;
    }
}
